#ifndef _ACCOUNT_HPP_20120616
#define _ACCOUNT_HPP_20120616

#include <ext/hash_map>

#include "singleton.hpp"
#include "acceptor_manager.hpp"
#include "processor.hpp"

#include "cmd_parser.hpp"
#include "confsvr_cmd.hpp"
#include "account_cmd.hpp"
#include "timer.hpp"

#include "basesvr.hpp"

using namespace tcp;
using namespace cmd;

typedef SSAccountResBody AccountConf;

struct LoginInfo
{
	ConnID          _conn_id;
	CSLoginReqBody  _req;
	Timer           _timer;
	uint32_t        _sequence;

	LoginInfo()
		: _conn_id(0),
		  _req(),
		  _timer(),
		  _sequence(0)
	{
	}
};

class Account : public BaseSvr, public Singleton<Account>
{
	public :
		friend class Singleton<Account>;

	public :
		typedef AcceptorManager<CmdParser, Processor<Account> > Reactor;
		typedef __gnu_cxx::hash_map<uint64_t, LoginInfo> LoginInfoMap;
		typedef LoginInfoMap::iterator LoginInfoMap_Iter;

	public :
		virtual ~Account() { finish(); }

		int regist();

		// should implement those function
		virtual int impl_init();
		virtual int process();
		virtual int reload();
		virtual int finish();
		
		Reactor * reactor()               { return _reactor; }

		uint32_t sequence() { return (++ _sequence); }

	public :
		Reactor         *  _reactor;

		AccountConf        _conf;

		ConnID             _dbsvr_conn;
		ConnID             _confsvr_conn;

		LoginInfoMap       _login_info_map;

		uint32_t           _sequence;
};

#endif

